package com.peralex.example;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import com.peralex.sharedlibs.dsphostl.TimeStamp;
import com.peralex.utilities.ui.graphs.waterfallGraph.IntensityWaterfallGraph;

/**
 *
 * @author Noel Grandin
 */
public class WaterfallGraphDemo extends javax.swing.JPanel {
  
	private final com.peralex.utilities.ui.graphs.graphBase.GraphWrapper graphWrapper;
  private final IntensityWaterfallGraph lineGraph;
  
  private static final int WATERFALL_WIDTH = 400;
  
  /** Creates new form GraphWithMultipleLines */
  public WaterfallGraphDemo() {
    initComponents();
    
    lineGraph = new IntensityWaterfallGraph();
    lineGraph.setGridXMinMax(0, 100);
    lineGraph.setThresholdLimits(0, 100);
    lineGraph.setThresholdValues(10, 90);
		lineGraph.setGridVisible(true);
		lineGraph.setZoomEnabled(true);
		
    graphWrapper = new com.peralex.utilities.ui.graphs.graphBase.GraphWrapper(lineGraph);
    graphWrapper.replaceYAxis(lineGraph.getWaterfallIntensityAxis());
    graphWrapper.setXAxisLabelVisible(false);
    graphWrapper.setXAxisScaleVisible(false);
    graphWrapper.setCursorCoordinatesVisible(false);
    graphWrapper.getXAxisExtraPanel().setVisible(false);
    graphWrapper.setAxisTitles("", "Waterfall_Time_Axis");
    graphWrapper.setTitle("Waterfall Graph with Intensity Axis");
    graphWrapper.setAxisTitlesAndUnits("X", "froobles", "Y", "bagets");
    
    graphPanel.add(graphWrapper, BorderLayout.CENTER);
    
    new javax.swing.Timer(50, new ActionListener() {
    	public void actionPerformed(ActionEvent e)
    	{
    		final float [] data = new float[WATERFALL_WIDTH];
    		for (int i=0; i<WATERFALL_WIDTH; i++) {
    			data[i] = (float) (Math.random() * 50);
    		}
    		data[(int)Math.round(WATERFALL_WIDTH * 0.4)] += 40;
    		data[(int)Math.round(WATERFALL_WIDTH * 0.6)] += 40;
    		
    		lineGraph.setAmplitudeData(new TimeStamp(), data);
    	}
    }).start();
  }
  
  /** This method is called from within the constructor to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the Form Editor.
   */
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    graphPanel = new javax.swing.JPanel();
    controlPanel = new javax.swing.JPanel();

    setLayout(new java.awt.BorderLayout());

    graphPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(4, 4, 4, 4));
    graphPanel.setLayout(new java.awt.BorderLayout());
    add(graphPanel, java.awt.BorderLayout.CENTER);

    controlPanel.setLayout(new java.awt.GridBagLayout());
    add(controlPanel, java.awt.BorderLayout.EAST);
  }// </editor-fold>//GEN-END:initComponents
  
  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JPanel controlPanel;
  private javax.swing.JPanel graphPanel;
  // End of variables declaration//GEN-END:variables
  
}
